<?php

/**
 * 
 */		
class Search_model extends CI_Model {
	
	function __construct() {
		parent::__construct();
	}
	
	function search(){
		$menotabulky = $_GET['menotabulky'];
		$searchString = $_GET['search'];
		if ($menotabulky=='odcestovani' || $menotabulky=='pricestovani') {
			$query = $this->db->query('SELECT * FROM '. $this->db->protect_identifiers($menotabulky) .' WHERE lower(concat_ws(\' \',city,country,organization)) LIKE \'%'. $this->db->escape_like_str($searchString) .'%\'');
		}
		else {
			// ?????????? WHAAAAAT!!! ?????????
            $query = $this->db->query('SELECT * FROM '. $this->db->protect_identifiers($menotabulky) .' WHERE lower(concat_ws(\' \',name,surname,department,email)) LIKE \'%'. $this->db->escape_like_str($searchString) .'%\'');
		}
		//print('SELECT * FROM '. $menotabulky .' WHERE lower(concat_ws(\' \',city,country,organization)) LIKE \'%'. $searchString .'%\'');
		//print_r($query); die();
		return $query->result_array();
	}
}
